import 'package:family_expense/features/income_expense/constants/payment_type.dart';
import 'package:family_expense/features/income_expense/widgets/income_expense_detail_shared.dart';
import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:my_flutter_core/my_flutter_core.dart';

/// Analysis summary card.
class IncomeExpenseAnalysisSummaryCard extends StatelessWidget {
  const IncomeExpenseAnalysisSummaryCard(
    this.income,
    this.expense,
    this.balance,
    this.paymentType, {
    super.key,
  });

  final double income;
  final double expense;
  final double balance;
  final String? paymentType;

  @override
  Widget build(BuildContext context) {
    return Card(
      child: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                IncomeExpenseDetailShared.getTypeIcon(
                      paymentType,
                      size: 18.0,
                    ) ??
                    Icon(MdiIcons.bellOutline, size: 18.0),
                const SizedBox(width: 4.0),
                Text(
                  PaymentType.getCategories()[paymentType] ?? '总计',
                  style: Theme.of(context).textTheme.titleSmall,
                ),
              ],
            ),
            const Divider(),
            Row(
              children: [
                const Text('收入'),
                Expanded(
                  child: Text(
                    '+${formatNumber(income)}',
                    textAlign: TextAlign.end,
                  ),
                ),
              ],
            ),
            const SizedBox(height: 4.0),
            Row(
              children: [
                const Text('支出'),
                Expanded(
                  child: Text(
                    formatExpenseNumber(expense),
                    textAlign: TextAlign.end,
                  ),
                ),
              ],
            ),
            const SizedBox(height: 4.0),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                AmountSymbol(
                  balance,
                  size: 12.0,
                  marginTop: 2.0,
                  color: IncomeExpenseDetailShared.getAmountColor(balance),
                ),
                Text(
                  formatNumber(balance.abs()),
                  style: TextStyle(
                    fontSize: 20.0,
                    fontWeight: FontWeight.bold,
                    color: IncomeExpenseDetailShared.getAmountColor(balance),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
